from flask_cors import CORS
import yaml
from flask import Flask

def load_config(config_path):
    with open(config_path, 'r', encoding='UTF-8') as file:
        config = yaml.safe_load(file)
        return config

def init_handle(app:Flask):
    from .controller import user
    user.user_handle(app)

def create_app():
    cfg=load_config('./config.yaml')
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        CONFIG=cfg,
    )

    CORS(app)
    from . import log
    log.setup_logging(app)
    from . import db
    db.init_app(app)
    init_handle(app)
    return app